@extends('admin.layouts.app')
@section('css')
    <link rel="stylesheet" href="https://cache.amap.com/lbs/static/main1119.css"/>
     <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.10&key=c5dac0d4761d48c299d7d86a9a84458b&plugin=AMap.Autocomplete,AMap.PlaceSearch,AMap.Geocoder">
     </script>
      <script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
    <script type="text/javascript" src="/js/plupload.full.min.js"></script>  
@endsection
@section('content')

                        <!-- Page-Title -->
                        <div class="row">
                            <div class="col-sm-12">
                                <h4 class="page-title">点位管理</h4>
                                <ol class="breadcrumb">
                                    <li><a href="#">系统</a></li>
                                    <li><a href="{{url('zadmin/billboard')}}">点位管理</a></li>
                                    <li class="active">添加点位</li>
                                </ol>
                            </div>
                        </div>
                        
                        <div class="row">
                          <div class="col-lg-12">
                            <div class="card-box">
                            <h2 class="m-t-0 header-title">添加点位</h2>
                            <hr/>
                             @if(session('rs'))
                              <div class="alert alert-{{session('rs')['status']}}">
                                {{ session('rs')['msg'] }}
                              </div>
                              @endif

                              <div class="row">
                                <div class="col-md-4">
                                   <form class="form-horizontal" role="form" action="{{url('zadmin/billboard')}}" method="post" enctype="multipart/form-data" id="form1">
                                    
                                            

                                              <div class="form-group">
                                                  <label class="control-label">名称</label>
                                                 
                                                      <input type="text" class="form-control" name="title" required="" value="">
                                                
                                              </div>
                                             
                                                   
                                                      
                                                  
                                             
                                              
          <div class="form-group">
          <label class="control-label">项目</label>
          <select class="form-control" name="category_id" required="">
            <option value="">请选择</option>
            @foreach($cates as $cate)
            <option value="{{$cate->id}}">{{$cate->name}}</option>
            @endforeach
          </select>                                      
          </div>


                                              

          <div class="form-group">
            <label class="control-label">地点</label>
              <input  class="form-control" name="address" value="" >
          </div>
                                              
    
    <div class="form-group">
      <label class="control-label">检查时间</label>                                         
      <input value="{{date('Y-m-d H:i')}}"  class="form-control" name="work_time" placeholder="用空格分割" >
                                                       
                                                 
    </div>

       <div class="form-group">
            <label class="control-label">视频</label>
              <input type="file"  class="form-control" name="video"  >
          </div>
    

    
    
                   

                   

                                                           

          
                                              
          <input name="lnglat" id="lnglat" type="hidden"  value="" />   
          <input name="pics"   id="pics"   type="hidden"  value=""  />                 
                             {{csrf_field()}}
        </form>
      </div>

                                <div class="col-md-8" style="padding: 10px;">
                                  <div id="container" style="height: 500px;"></div>
                                    <div id="myPageTop">
                                        <table>
                                            <tr>
                                                <td>
                                                    <label>请输入关键字：</label>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <input id="tipinput"/>
                                                </td>
                                            </tr>
                                        </table>
                                    </div>                                  
                                </div>

                              </div>

                             
                              
                              
                            </div>
                           <div class="form-group">
            <button type="submit" class="btn btn-info btn-submit">保存</button>
          </div>     
                            </div> <!-- end col -->

                            
                        </div>
@endsection
                        
                        
                        

                  
            
      
       

           



    
        @section('js')

        <script type="text/javascript">
          $('.btn-submit').on('click',function(){
            $('#form1').submit();
          })
        pics = '';
          var uploader = new plupload.Uploader({
              runtimes : 'html5,flash,silverlight,html4',
              browse_button : 'pickfiles', // you can pass an id...
              container: document.getElementById('container'), // ... or DOM Element itself
              url : '/upload.php',
              flash_swf_url : '../js/Moxie.swf',
              silverlight_xap_url : '../js/Moxie.xap',
              
              filters : {
                max_file_size : '10mb',
                mime_types: [
                  {title : "Image files", extensions : "jpg,gif,png"},
                  {title : "Zip files", extensions : "zip"}
                ]
              },

              init: {
                PostInit: function() {
                  $('#filelist').html('');

                  
                },

                FilesAdded: function(up, files) {
                  plupload.each(files, function(file) {
                    $('#filelist').html('<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>');
                     uploader.start();
                     return false;
                  });
                },

               

                 FileUploaded: function(up, file, info) {
                            // Called when file has finished uploading
                              var rs =  JSON.parse(info.response);
                              if(rs.status){
                                //console.info(rs.data);
                                var str = '<img style="padding:5px" src="'+rs.data+'" width="100">';
                                $('.piclist').append(str);
                                pics += rs.data+',';
                                $('#pics').val(pics);
                              }
                              console.info(rs);
                              
                },

                
                 

                
              }
            });

uploader.init();          
         
        var geocoder = new AMap.Geocoder({
              // city 指定进行编码查询的城市，支持传入城市名、adcode 和 citycode
             
        })
        //地图加载
        var map = new AMap.Map("container", {
            resizeEnable: true, 
            center: [121.467756,31.221631],//中心点坐标   
            zoom : 11      
        });

        
       
         

          
          //输入提示
          var autoOptions = {
              input: "tipinput"
          };
          var auto = new AMap.Autocomplete(autoOptions);
          var placeSearch = new AMap.PlaceSearch({
              map: map
          });  //构造地点查询类
          AMap.event.addListener(auto, "select", select);//注册监听，当选中某条记录时会触发
          function select(e) {
              placeSearch.setCity(e.poi.adcode);
              placeSearch.search(e.poi.name);  //关键字查询查询
          }

          map.on('click', function(e) {
              markers = map.getAllOverlays('marker');
              if(markers) {
                map.remove(markers)
              }
              document.getElementById("lnglat").value = e.lnglat.getLng() + ',' + e.lnglat.getLat();
              lnglat = e.lnglat;
              marker = new AMap.Marker({
                  icon: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png",
                  position: lnglat,
                  offset: new AMap.Pixel(-13, -30)
              });
              marker.setMap(map);
              geocoder.getAddress(lnglat, function(status, result) {
              if (status === 'complete' && result.info === 'OK') {
                  var address = result.regeocode.formattedAddress;
                  $('input[name="title"]').val(address);
                  $('input[name="address"]').val(address);
              }
            })
          });


        </script>

     
         

          
       
        @endsection
    
